package com.itboye.jigongbao.adpapter

import android.content.Context
import android.text.Html
import com.itboye.jigongbao.R
import com.itboye.jigongbao.adpapter.baseAdapter.MutiplyCommonAdapter
import com.itboye.jigongbao.adpapter.baseAdapter.ViewHolder
import com.itboye.jigongbao.bean.JiYiBiBean
import com.itboye.jigongbao.utils.ByTimeUtils.timeFormat
import org.json.JSONObject

@Suppress("DEPRECATION")
/**
 * Created by Administrator on 2017/11/29.
 */
class WagesBillsListAdapter(private val context: Context, datas: List<JiYiBiBean.JiYiBiEntity>, vararg layoutId: Int) : MutiplyCommonAdapter<JiYiBiBean.JiYiBiEntity>(context, datas, layoutId[0]) {

    override fun getItemViewType(position: Int): Int {
        return 0
    }

    override fun getItemPosition(position: Int) {
    }

    override fun convert(holder: ViewHolder?, t: JiYiBiBean.JiYiBiEntity?, type: Int, position: Int) {
        holder!!.setText(R.id.tv2, t!!.overseer_name)
        holder!!.setText(R.id.tv3, timeFormat("yyyyMMdd", "yyyy-MM-dd", t!!.daytime))
        var extra: JSONObject? = null
        try {
            extra = JSONObject(t!!.extra)
        } catch (e: Exception) {

        }
        var money = t!!.money / 100
        if (this.mParam1 == "1") {
            holder!!.setVisible(R.id.re_4, false)
        } else {
            holder!!.setVisible(R.id.re_4, true)
        }
        when (t!!.item_type_key) {
            "00S002003" -> {
                //点工
                var gong = 0
                if (extra!!.has("normal_worktime")) {
                    gong += extra.getString("normal_worktime").toInt() / 8
                }
                if (extra.has("over_worktime")) {
                    gong += extra.getString("over_worktime").toInt() / 6
                }
                holder!!.setText(R.id.tv4, "（${gong}个工）点工")
                var hourly_wage = 0//工资标准
                if (extra.has("hourly_wage")) {
                    hourly_wage=extra.getInt("hourly_wage")
                }
            }
            "00S002002" -> {
                //包工
                var gong = 0
                if (extra!!.has("normal_worktime")) {
                    gong += extra.getString("normal_worktime").toInt() / 8
                }
                if (extra.has("over_worktime")) {
                    gong += extra.getString("over_worktime").toInt() / 6
                }
                holder!!.setText(R.id.tv4, "（${gong}个工）包工")
            }
            "00S002004" -> {
                //借支
                holder!!.setText(R.id.tv4, "借支")
            }
            "00S002005" -> {
                //结算
                holder!!.setText(R.id.tv4, "结算")
            }
            else -> {
            }
        }

        if (t!!.money >= 0) {
            holder!!.setTextColor(R.id.tv5, context.resources.getColor(R.color.gallery_green))
            holder!!.setText(R.id.tv5, Html.fromHtml("+￥${t!!.money / 100}"))
        } else {
            holder!!.setTextColor(R.id.tv5, context.resources.getColor(R.color.gallery_red))
            holder!!.setText(R.id.tv5, Html.fromHtml("-￥${t!!.money / 100}"))
        }
    }

    private lateinit var mParam1: String

    fun setType(mParam1: String) {
        this.mParam1 = mParam1
    }
}